const { Schema } =require("mongoose")
let mongoose =require("./db")
const bcryptjs = require("bcryptjs");

let ArticleSchema=new Schema({
    title:String, // 文章标题
    name:String, // 作者名
    pic:String, // 图片
    cnum:Number, // 数量
    cls:String, // 分类
    timer:{ // 时间
        type:Date,
        default:Date.now()
    },
    coll:{ // 是否收藏
        type:Boolean,
        default:false
    },
    status:{ // 是否关注
        type:Boolean,
        default:false
    },
    like:{ // 是否点赞
        type:Boolean,
        default:false
    },
    context:String // 内容
})

let commentSchema=new Schema({
    name:String,
    text:String,
    pic:String,
    timer:{
        type:Date,
        default:Date.now()
    },
    likenum:{
        type:Number,
        default:0
    },
    com:{
        type:Schema.Types.ObjectId,
        ref:'comment'
    },
    user:{
        type:Schema.Types.ObjectId,
        ref:'user'
    }
})

// 用户表
const userSchema = new mongoose.Schema({
    username: String, // 用户
    password: {
        type: String,
        set(val) { return bcryptjs.hashSync(val) }
    },
    phone:{
        type:String,
        default:'13312341234'
    },
    nickname:{
        type:String,
        default:'用户*'
    },
    uid:{
        type:String,
        default:Date.now()
    }
})


let ArticleModel =mongoose.model("article",ArticleSchema,"article")
let commentModel=mongoose.model("comment",commentSchema,"comment")
let userModel=mongoose.model("user",userSchema,"user")

// userModel.create({
//     username: 'sanzu',
//     password: 'sanzu',
//     phone: '13212341234',
//     nickname:'嘴爱编程者',
// })

module.exports={ArticleModel,commentModel,userModel}